﻿@model PaymentTransactionListModel
@inject AdminAreaSettings adminAreaSettings
@{
    //page title
    ViewBag.Title = Loc["Admin.Orders.PaymentTransaction"];
}
<form asp-area="@Constants.AreaAdmin" asp-controller="PaymentTransaction" asp-action="List" method="post">

    <div class="row">
        <div class="col-md-12">
            <div class="x_panel light form-fit popup-window">
                <div class="x_title">
                    <div class="caption level-caption">
                        <i class="fa fa-truck"></i>
                        @Loc["Admin.Orders.PaymentTransaction"]
                    </div>
                    <vc:admin-widget widget-zone="payment_transaction_list_buttons" additional-data="null"/>
                </div>
                <div class="x_content form">
                    <div class="form-horizontal">
                        <div class="form-body">
                            <div class="main-header col-12 px-0">
                                <div class="row align-items-end">
                                    <div class="col-md-4 col-ms-12 col-12">
                                        <div class="form-group mb-0">
                                            <admin-label asp-for="SearchCustomerEmail" class="control-label"/>
                                            <admin-input asp-for="SearchCustomerEmail"/>
                                        </div>
                                    </div>
                                    <div class="col-md-4 col-ms-12 col-12">
                                        <div class="form-group mb-0">
                                            <admin-label asp-for="OrderNumber" class="control-label"/>
                                            <div class="input-group mb-0" style="text-align:left">
                                                <admin-input asp-for="OrderNumber"/>
                                                <span class="input-group-append">
                                                    <input type="submit" id="go-to-ordernumber" asp-action="GoToOrderNumber" name="go-to-ordernumber" class="btn default" value="@Loc["Admin.Common.Go"]"/>
                                                </span>
                                            </div>
                                        </div>
                                    </div>
                                    <div class="col-md-4 col-sm-12 col-12">
                                        <div class="form-actions">
                                            <div class="btn-group">
                                                <button class="btn btn-success filter-submit" id="search-paymenttransaction">
                                                    <i class="fa fa-search"></i> @Loc["Admin.Common.Search"]
                                                </button>
                                                <button class="btn btn-info" type="button" data-toggle="collapse" data-target="#filterCollapse" aria-expanded="false" aria-controls="filterCollapse">
                                                    <i class="fa fa-filter"></i>&nbsp; @Loc["Admin.Common.Filters"]
                                                </button>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <div class="collapse" id="filterCollapse">
                            <div class="drop-filters-container w-100">
                                <div class="form-group">
                                    <admin-label asp-for="StartDate" class="col-sm-3 control-label"/>
                                    <div class="col-md-9 col-sm-9">
                                        <admin-input asp-for="StartDate"/>
                                    </div>
                                </div>
                                <div class="form-group">
                                    <admin-label asp-for="EndDate" class="col-sm-3 control-label"/>
                                    <div class="col-md-9 col-sm-9">
                                        <admin-input asp-for="EndDate"/>
                                    </div>
                                </div>
                                <div class="form-group">
                                    <admin-label asp-for="SearchTransactionStatus" class="col-sm-3 control-label"/>
                                    <div class="col-md-9 col-sm-9">
                                        <admin-select asp-for="SearchTransactionStatus" asp-items="Model.PaymentTransactionStatus"/>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="x_content form">
                    <div class="x_content">
                        <div id="paymenttransactions-grid"></div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</form>
<script>
    $(document).ready(function() {
        $("#paymenttransactions-grid").kendoGrid({
            dataSource: {
                transport: {
                    read: {
                        url: "@Html.Raw(Url.Action("List", "PaymentTransaction", new { area = Constants.AreaAdmin }))",
                        type: "POST",
                        dataType: "json",
                        data: additionalData
                    }
                },
                schema: {
                    data: "Data",
                    total: "Total",
                    errors: "Errors"
                },
                error: function(e) {
                    display_kendoui_grid_error(e);
                    // Cancel the changes
                    this.cancelChanges();
                },
                pageSize: @(adminAreaSettings.DefaultGridPageSize),
                serverPaging: true,
                serverFiltering: true,
                serverSorting: true
            },
            pageable: {
                refresh: true,
                pageSizes: [@(adminAreaSettings.GridPageSizes)]
            },
            editable: {
                confirmation: false,
                mode: "inline"
            },
            scrollable: false,
            columns: [
                 {
                    field: "PaymentMethodSystemName",
                    title: "@Loc["Admin.Orders.PaymentTransaction.Fields.PaymentMethodSystemName"]",
                    width: 80,
                    template: '<a class="k-link" href="Edit/#=Id#">#=PaymentMethodSystemName#</a>'
                }, {
                    field: "TransactionAmount",
                    title: "@Loc["Admin.Orders.PaymentTransaction.Fields.TransactionAmount"]",
                    width: 80,
                    template: '<a class="k-link" href="Edit/#=Id#">#=kendo.toString(TransactionAmount, "n2")# #=CurrencyCode#</a>'
                }, {
                    field: "PaidAmount",
                    title: "@Loc["Admin.Orders.PaymentTransaction.Fields.PaidAmount"]",
                    width: 100,
                    template: '<a class="k-link" href="Edit/#=Id#">#=kendo.toString(PaidAmount, "n2")# #=CurrencyCode#</a>'
                }, {
                    field: "CustomerId",
                    title: "@Loc["Admin.Orders.PaymentTransaction.Fields.Customer"]",
                    width: 200,
                    template: '<a class="k-link" href="@Url.Action("Edit", "Customer", new { area = Constants.AreaAdmin })/#=CustomerId#">#:kendo.htmlEncode(CustomerEmail)#</a>'
                }, {
                    field: "OrderNumber",
                    title: "@Loc["Admin.Orders.PaymentTransaction.Fields.OrderNumber"]",
                    width: 80,
                    template: '<a class="k-link" href="@Url.Action("Edit", "Order", new { area = Constants.AreaAdmin })/#=OrderId#">#:OrderNumber#</a>'
                }, {
                    field: "Status",
                    title: "@Loc["Admin.Orders.PaymentTransaction.Fields.Status"]",
                    width: 130,
                    template: '<a class="k-link" href="Edit/#=Id#">#=Status#</a>'
                }, {
                    field: "CreatedOn",
                    title: "@Loc["Admin.Orders.PaymentTransaction.Fields.CreatedOn"]",
                    width: 100,
                    type: "date",
                    format: "{0:G}"
                }
            ]
        });
    });
</script>

<script>
    function additionalData() {
        var data = {
            SearchTransactionStatus: $('#@Html.IdFor(model => model.SearchTransactionStatus)').val(),
            SearchCustomerEmail: $('#@Html.IdFor(model => model.SearchCustomerEmail)').val(),
            OrderNumber: $('#@Html.IdFor(model => model.OrderNumber)').val(),
            StartDate: $('#@Html.IdFor(model => model.StartDate)').val(),
            EndDate: $('#@Html.IdFor(model => model.EndDate)').val()
        };
        addAntiForgeryToken(data);
        return data;
    }
    $(document).ready(function () {
        $('#search-paymenttransaction').click(function () {
            //search
            var grid = $('#paymenttransactions-grid').data('kendoGrid');
            grid.dataSource.page(1); //new search. Set page size to 1
            //grid.dataSource.read(); we already loaded the grid above using "page" function
            return false;
        });

        $("#@Html.IdFor(model => model.SearchCustomerEmail)").keydown(function (event) {
            if (event.keyCode == 13) {
                $("#search-paymenttransaction").click();
                return false;
            }
        });
        $("#@Html.IdFor(model => model.OrderNumber)").keydown(function (event) {
            if (event.keyCode == 13) {
                $("#go-to-ordernumber").click();
                return false;
            }
        });
    });
</script>